// 墙canvas子类
import canvasAbstract from './canvasAbstract';
import config from '../config';
import bulletModel from '../model/bullet';
import tank from './tank';
import play from './play';
import audios from '../service/audios';
export default new (class bullet extends canvasAbstract implements ICanvas{
  name = 'bullet';
  setIntervalID = 0;
  num(): number {
    return 0;
  }
  model(): BulletModelInterface {
    return bulletModel;
  }
  render() {
    this.setIntervalID = setInterval((_: any) => {
      this.createModel();
      super.renderModel();
    }, config.bullet.speed || 50);
  };
  createModel() {
    tank.modelist.forEach(tank => {
      let isExists = this.modelist.some(m => m.tank === tank);
      !isExists && this.modelist.push(new bulletModel(tank));
    });
  };
  addPlayBullet() {
    if (play.modelist.length <= 0) return;
    audios.fire();
    this.modelist.push(new bulletModel(play.modelist[0]));
  };
  stop() {
    clearInterval(this.setIntervalID);
  }
})('bullet');